<template>
	<view class="bg-white ">


		<u-cell :titleStyle="{'alignItems':'normal'}">
			<view slot="icon">
				<image class="image" width="60" height="60" :src="item.image" radius="10"></image>
			</view>
			<view slot="title" style="width: 100%;">
				<text class="font-size-12 text-indent">{{item.name}}</text>
			</view>

			<view slot="label" class="labelLine text-indent">
				<view>
					<text class="u-error">{{item.price?item.price:item.marketPrice}}￥</text>
				</view>
				<view>
			
					<view  v-if="isShopBuy==false" @click="shopbuy">
								<iconfont :color="color.primary" icon="icon-tianjia1" size="25" />
					</view>
					<!-- <u-number-box name="1" value="0" :min="0" @change="valChange" buttonSize="25">
						<view slot="minus" class="minus">
							<u-icon name="minus" size="12"></u-icon>
						</view>
						<text slot="input" style="width: 30px;text-align: center;" class="input">{{value}}</text>
						<view slot="plus" class="plus">
							<u-icon name="plus" color="#FFFFFF" size="12"></u-icon>
						</view>
					</u-number-box> -->
				</view>
			</view>


		</u-cell>


	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				value: 0,
				isShopBuy:false
			}
		},
		mounted: function() {
			var shopbuylist = uni.getStorageSync("shopbuylist") || []
			var filteredArray = shopbuylist.filter(value => value.id > res.id);
			if (filteredArray.length > 0) {
				this.isShopBuy = true
			}
		},

		methods: {
			valChange: function(e) {
				console.log(e)
				this.item.quantity = e.value
				//this.item.price=//uni.$u.priceFormat(this.item.price,2)
				this.value = e.value
				var op = {
					value: e.value,
					item: this.item
				}
				this.$emit("action", op)
			},

			shopbuy: function() {
				var shopbuylist = uni.getStorageSync("shopbuylist") || []

				var filteredArray = shopbuylist.filter(value => value.id == this.item.id);
				if (filteredArray.length > 0) {
					this.isShopBuy = true
				} else {
					shopbuylist.push(this.item)
					uni.setStorageSync("shopbuylist", shopbuylist)
					this.isShopBuy = true
				}
				uni.showToast({
					title: this.$t("添加购物车")
				})

			},
		}
	}
</script>


<style lang="scss">
	.minus {
		width: 22px;
		height: 22px;
		border-width: 1px;
		border-color: #E6E6E6;
		border-style: solid;
		border-top-left-radius: 100px;
		border-top-right-radius: 100px;
		border-bottom-left-radius: 100px;
		border-bottom-right-radius: 100px;
		@include flex;
		justify-content: center;
		align-items: center;
	}

	.input {
		padding: 0 5px;
	}

	.plus {
		width: 22px;
		height: 22px;
		background-color: #FF0000;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}

	.labelLine {
		display: flex;
		justify-content: space-between;
		overflow: revert;

	}

	.image {
		width: 60px;
		height: 60px;
		background-color: #E6E6E6;
		border-radius: 10px;
	}

	.text-indent {
		text-indent: 10px;
	}
</style>